rm(list=ls())
set.seed(1234)
library(car)
library(plyr)
library(ggplot2)
library(psycho)
library(texreg)
library(effectsize)
library(foreign)
library(xtable)

#Load Dynata data

setwd("/Users/amandaclayton/Dropbox/All Male Panels/3 - Women Grab Back/1 - WGB Paper 2020/Data and Replication Code/Dataverse upload/dataverse_files")

modeldata<-read.csv("Dynata.csv")

#Recode / clean data 

modeldata$abortion_support<-recode(modeldata$Q10_1, " 'A good idea' = 0; 'A bad idea' =1")

modeldata$treat<-recode(modeldata$Treatments_DO, " 'amp_energy|new_memb|efficacy|qual|race_interest'= 'amp_energy'; 'amp_repro|new_memb|efficacy|qual|race_interest' = 'amp_repro'; 'gbp_energy|new_memb|efficacy|qual|race_interest' = 'gbp_energy'; 'gbp_repro|new_memb|efficacy|qual|race_interest' = 'gbp_repro' ")

modeldata$amb_post<-recode(modeldata$amb_post, " 'It is something I am unlikely to do.' = 1; 'I would not rule it out forever, but I currently have no interest.' = 2; 'It is something I might undertake if the opportunity presented itself.' =3; 'It is something I definitely would like to undertake in the future.' =4 ")

modeldata$amb_post<-as.numeric(as.character(modeldata$amb_post))

modeldata$amb_pre<-recode(modeldata$amb_pre, " 'It is something I am unlikely to do.' = 1; 'I would not rule it out forever, but I currently have no interest.' = 2; 'It is something I might undertake if the opportunity presented itself.' =3; 'It is something I definitely would like to undertake in the future.' =4 ")

modeldata$amb_pre <-as.numeric(as.character(modeldata$amb_pre))

modeldata$female<-recode(modeldata$gender, " 'Woman' = 1; else =0" )

modeldata$gbp<-recode(modeldata$treat, " c('gbp_repro', 'gbp_energy') = 1; else = 0")
modeldata$gbp <-as.numeric(as.character(modeldata$gbp))

modeldata$amp<-recode(modeldata$treat, " c('amp_repro', 'amp_energy') = 1; else = 0")
modeldata$amp <-as.numeric(as.character(modeldata$amp))

modeldata$repro<-recode(modeldata$treat, " c('amp_repro', 'gbp_repro') = 1; else = 0")
modeldata$repro <-as.numeric(as.character(modeldata$repro))

modeldata$energy<-recode(modeldata$treat, " c('amp_energy', 'gbp_energy') = 1; else = 0")
modeldata$energy <-as.numeric(as.character(modeldata$energy))


#from strongly disargree to strongly agree 

modeldata[modeldata =="Strongly disagree"]<-1
modeldata[modeldata =="Disagree"]<-2
modeldata[modeldata =="Agree"]<-3
modeldata[modeldata =="Strongly agree"]<-4

modeldata[modeldata =="Not at all  interested"]<-1
modeldata[modeldata =="Not at all interested"]<-1
modeldata[modeldata =="Not very  interested"]<-2
modeldata[modeldata =="Somewhat interested"]<-3
modeldata[modeldata =="Very interested"]<-4

modeldata[modeldata =="Fewer women"]<-1
modeldata[modeldata =="The number is just about right"]<-2
modeldata[modeldata =="More women"]<-3

modeldata[,14:20] <- sapply(modeldata[,14:20],as.numeric)

modeldata$amb_pre_stand <-standardize(modeldata$amb_pre)
modeldata$amb_post_stand <-standardize(modeldata$amb_post)

modeldata$ideo_scale<-recode(modeldata$ideo, " 'Very liberal' = 1; 'Somewhat liberal' = 2; 'Liberal' = 3; 'Middle of the road' = 4; 'Not sure' = 4; 'Conservative' = 5; 'Somewhat conservative' = 6; 'Very conservative' = 7")

modeldata$Dem <-recode(modeldata$pt_id, "'Democrat' = 1; else =0")
modeldata$LeanDem <-recode(modeldata$close_party, "'The Democratic Party' = 1; else =0")
modeldata$LeanDem <- modeldata$LeanDem + modeldata$Dem

modeldata$Rep <-recode(modeldata$pt_id, "'Republican' = 1; else =0")
modeldata$LeanRep <-recode(modeldata$close_party, "'The Republican Party' = 1; else =0")
modeldata$LeanRep <- modeldata$Rep + modeldata$LeanRep

modeldata$feminist<-recode(modeldata$feminist, " 'Not at all' = 1; 'Not very well' = 2; 'Somewhat well'= 3; 'Very well' = 4; 'Extremely well' =5 " ) #higher values --> the term feminist describes R well


modeldata$clicked_out<-as.numeric(as.character(modeldata$clicked_out))

modeldata$Run_Make_Difference <-recode(modeldata$amb_reason, " 'I would run where I could make the biggest difference.' = 1; else =0 " )
modeldata$Run_Enjoy<-recode(modeldata$amb_reason, " 'I would run where the position would be most enjoyable.' = 1; else =0 " )
modeldata$Run_Win <-recode(modeldata$amb_reason, " 'I would run where I think I could win.' = 1; else =0 " )

modeldata$amb_reason<-recode(modeldata$amb_reason, " 'Other' = NA ")

modeldata$age<-as.numeric(as.character(modeldata$age))

##By party: 1= Dem, 2 = lean Dem, 3 = tru I, 4 = lean Rep, 5 = Rep

modeldata$party_scale<-recode(modeldata$pt_id, " 'Democrat' =1; 'Other' =3; 'Republican' =5 ; else=0")
modeldata$party_scale<-as.numeric(as.character(modeldata$party_scale))

temp<-recode(modeldata$close_party, " 'The Democratic Party' = 2; 'The Republican Party' =4; c('Neither', 'Not sure')=3; else=0 ")
modeldata$party_scale<-modeldata$party_scale + temp
modeldata$party_scale<-recode(modeldata$party_scale, " 9 = NA")

modeldata$strong_dem_recode<-recode(modeldata$strong_dem, " 'Strong Democrat' = -2; 'Not so strong Democrat' = -1; else =0 ")
modeldata$strong_rep_recode<-recode(modeldata$strong_rep, " 'Strong Republican' = 2; 'Not so strong Republican' = 1; else =0 ")

modeldata$party_scale2<-modeldata$party_scale + modeldata$strong_dem_recode + modeldata$strong_rep_recode
modeldata$party_scale2<-recode(modeldata$party_scale2, "  -1=1; 0 =2; 2 =3; 3=4; 4=5 ")

#Recode political interest 

modeldata$pol_interest_scale<-recode(modeldata$pol_interest, " 'Hardly at all' = 1; 'Only now and then' = 2; 'Some of the time' = 3; 'Most of the time' =4 ")

#recode education scale 

modeldata$edu_scale<-recode(modeldata$edu, " c('Did not graduate from high school',  'High school graduate') = 1; 'Some college, but no degree (yet)' = 2; '2-year college degree' = 3; '4-year college degree' = 4; 'Postgraduate degree (MA, MBA, MD, JD, PhD, etc.)' = 5  ")

#Create different subsets of respondents to create article figures 

women<-subset(modeldata, female==1)
men<-subset(modeldata, female==0)

#By party ID

DemW<-subset(women, pt_id =="Democrat")
LeanDemW<-subset(women, close_party =="The Democratic Party")
IndW<-subset(women, close_party =="Neither")
LeanRepW<-subset(women, pt_id =="Republican")
RepW<-subset(women, close_party =="The Republican Party")


#By gender / issue area treatment

Repro<-subset(modeldata, treat== "gbp_repro" | treat=="amp_repro" )
Energy<-subset(modeldata, treat== "gbp_energy" | treat=="amp_energy" )

Repro2<-subset(Repro, Repro$man_check_pol == "Women\x89۪s reproductive health ")

womenRepro<-subset(Repro2, female==1)
menRepro<-subset(Repro2, female==0)

womenEnergy<-subset(Energy, female==1)
menEnergy<-subset(Energy, female==0)


#by gender / gender-composition treatment (amp v. gbp)
womenRepro_AMP<-subset(womenRepro, amp==1)
womenRepro_GBP<-subset(womenRepro, amp==0)

#women energy
womenEnergyAMP<-subset(womenEnergy, amp==1)
womenEnergyGBP<-subset(womenEnergy, amp==0)

women<-subset(women, man_check_pol =="Renewable energy" | man_check_pol == "Women\x89۪s reproductive health ")
women<-rbind(womenRepro, womenEnergy)

#men repro 
menRepro_AMP<-subset(menRepro, amp==1)
menRepro_GBP<-subset(menRepro, amp==0)

#men energy
menEnergyAMP<-subset(menEnergy, amp==1)
menEnergyGBP<-subset(menEnergy, amp==0)

#by pre-treatment candidate type
WomenMakeDiff<-subset(women, Run_Make_Difference ==1) 
WomenMakeDiff_Repro<-subset(women, Run_Make_Difference ==1 & repro ==1) 
WomenEnjoy_Repro<-subset(women, Run_Enjoy ==1 & repro ==1)
WomenWin_Repro<-subset(women, Run_Win ==1 & repro ==1) 

WomenMakeDiff_Energy<-subset(women, Run_Make_Difference ==1 & repro ==0) 
WomenEnjoy_Energy<-subset(women, Run_Enjoy ==1 & repro ==0) 
WomenWin_Energy<-subset(women, Run_Win ==1 & repro ==0) 


###Begin Analysis for Dynata data
##This code first reproduces all the tables in the manuscript using the Dynata data (Tables 1 - 3), and then reproduces all of the figures in manuscript using the Dynata data (Figures 1 -9). The next section produces the table using the CES data (Table 4). 

##Table 1 (women respondents)

model1<-lm(race_interest ~ amp + repro + I(amp * repro), data=women) #sig at 0.058.
summary(model1) 

model2<-lm(amb_post ~ amb_pre + amp + repro + I(amp * repro), data=women)
summary(model2) 

model3<-lm(clicked_out ~ amp + repro + I(amp * repro), data=women) #
summary(model3) 

screenreg(list(model1, model2, model3), stars = c(0.01, 0.05, 0.1), digits = 3)
texreg(list(model1, model2, model3), stars = c(0.01, 0.05, 0.1), digits = 3)


#Table 2 (men respondents)

men1<-lm(race_interest ~ amp + repro + I(amp * repro), data=men)
summary(men1) 

men2<-lm(amb_post ~ amb_pre + amp + repro + I(amp * repro), data=men)
summary(men2) 

men3<-lm(clicked_out ~ amp + repro + I(amp * repro), data=men) 
summary(men3) 

screenreg(list(men1, men2, men3), stars = c(0.01, 0.05, 0.1), digits = 3)
texreg(list(men1, men2, men3), stars = c(0.01, 0.05, 0.1), digits = 3)


#Table 3 (efficacy women respondents)

lm3<-lm(efficacy ~ amp + repro + I(amp * repro), data=women) 
summary(lm3) 

screenreg(list(lm3), stars = c(0.01, 0.05, 0.1), digits = 3)
texreg(list(lm3), stars = c(0.01, 0.05, 0.1), digits = 3)


##Code used to create images 
## Gives count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%).
##   data: a data frame.
##   measurevar: the name of a column that contains the variable to be summariezed
##   groupvars: a vector containing names of columns that contain grouping variables
##   na.rm: a boolean that indicates whether to ignore NA's
##   conf.interval: the percent range of the confidence interval (default is 95%)
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
                      conf.interval=.95, .drop=TRUE) {

    # New version of length which can handle NA's: if na.rm==T, don't count them
    length2 <- function (x, na.rm=FALSE) {
        if (na.rm) sum(!is.na(x))
        else       length(x)
    }

    # This does the summary. For each group's data frame, return a vector with
    # N, mean, and sd
    datac <- ddply(data, groupvars, .drop=.drop,
      .fun = function(xx, col) {
        c(N    = length2(xx[[col]], na.rm=na.rm),
          mean = mean   (xx[[col]], na.rm=na.rm),
          sd   = sd     (xx[[col]], na.rm=na.rm)
        )
      },
      measurevar
    )

    # Rename the "mean" column    
    datac <- rename(datac, c("mean" = measurevar))

    datac$se <- datac$sd / sqrt(datac$N)  # Calculate standard error of the mean

    # Confidence interval multiplier for standard error
    # Calculate t-statistic for confidence interval: 
    # e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
    ciMult <- qt(conf.interval/2 + .5, datac$N-1)
    datac$ci <- datac$se * ciMult

    return(datac)
}

##Figure 2 (treatment effects on interest in the hypothetical race)

data_sum1 <- summarySE(womenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right

plot1<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(2, 3)) +
    ggtitle("Reproductive health \n Women respondents") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

##Women Energy

data_sum1 <- summarySE(womenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot2<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(2, 3)) +
    ggtitle("Renewable energy \n Women respondents") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

library(grid)
library(gridExtra)

grid.arrange(plot1 + annotate("text", x=0.975, y=2.6, label= "Gender-Balanced Council") + annotate("text", x = 1.025, y=2.85, label = "All-Male Council"), plot2 + annotate("text", x=0.975, y=2.57, label= "Gender-Balanced Council") + annotate("text", x = 1.025, y=2.45, label = "All-Male Council"), ncol=2)


##Figure 3 (movement from pre- to post-ambition levels )

data_sum1 <- summarySE(womenRepro, measurevar="amb_pre", groupvars=c("amp"))
data_sum2 <- summarySE(womenRepro, measurevar="amb_post", groupvars=c("amp"))

names(data_sum2)<-names(data_sum1)
data_sum<-rbind(data_sum1, data_sum2)

data_sum$post<-c(0,0,1,1)

data_sum$amp2<-c("GBP", "AMP", "GBP", "AMP")
data_sum$Treatment<-c("Gender-balanced", "All-male", "Gender-balanced", "All-male")

# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right

plot1<-ggplot(data_sum, aes(x=post, y=amb_pre, colour= Treatment, group=amp2)) + 
    geom_errorbar(aes(ymin= amb_pre-se, ymax= amb_pre +se), width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=16) + 
    xlab("Pre v. Post Treatment") +
    ylab("Average Ambition") +
        expand_limits(y=1.15:2.15) +                        # Expand y range
    ggtitle("Reproductive health \n Women respondents") +
    scale_colour_grey(end= 0.7) +
    theme_bw() +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())+ 
        theme(legend.position = c(0.24, 0.88))+
        guides(shape = guide_legend(override.aes = list(size = 0.6))) +
        guides(color = guide_legend(override.aes = list(size = 0.6))) +
        theme(legend.title = element_text(size = 10), 
               legend.text = element_text(size = 10))

##Women Energy

data_sum1 <- summarySE(womenEnergy, measurevar="amb_pre", groupvars=c("amp"))
data_sum2 <- summarySE(womenEnergy, measurevar="amb_post", groupvars=c("amp"))

names(data_sum2)<-names(data_sum1)
data_sum<-rbind(data_sum1, data_sum2)

data_sum$post<-c(0,0,1,1)

data_sum$amp2<-c("GBP", "AMP", "GBP", "AMP")
data_sum$Treatment<-c("Gender-balanced", "All-male", "Gender-balanced", "All-male")

# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right


plot2<-ggplot(data_sum, aes(x=post, y=amb_pre, colour= Treatment, group=amp2)) + 
    geom_errorbar(aes(ymin= amb_pre-se, ymax= amb_pre +se), width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=16) + 
    xlab("Pre v. Post Treatment") +
    ylab("Average Ambition") +
        expand_limits(y=1.15:2.15) +                        # Expand y range
    ggtitle("Renewable energy \n Women respondents") +
    scale_colour_grey(end= 0.7) +
    theme_bw() +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())+ 
        theme(legend.position = c(0.24, 0.88))+
        guides(shape = guide_legend(override.aes = list(size = 0.6))) +
        guides(color = guide_legend(override.aes = list(size = 0.6))) +
        theme(legend.title = element_text(size = 10), 
               legend.text = element_text(size = 10))

require(gridExtra)
grid.arrange(plot1 + annotate("text", x=0.07, y=1.7, label= "Pre-Treatment", cex=3) + annotate("text", x = 0.9, y=1.85, label = "Post-Treatment", cex=3), plot2+ annotate("text", x=0.07, y=1.75, label= "Pre-Treatment", cex=3) + annotate("text", x = 0.9, y=1.85, label = "Post-Treatment", cex=3), ncol=2)


##Figure 4 

womenRepro$clicked_out_per<-womenRepro$clicked_out * 100 #Make axis 1-100 to reflect percentage

data_sum1 <- summarySE(womenRepro, measurevar="clicked_out_per", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")


# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right

plot1<-ggplot(data_sum1, aes(x=1, y= clicked_out_per, group=amp2)) + 
    geom_errorbar(aes(ymin= clicked_out_per-se, ymax= clicked_out_per +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Click-out rate") +
scale_y_continuous(limits = c(0, 10)) +
    ggtitle("Reproductive health \n Women respondents") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())


##Women Energy

womenEnergy $clicked_out_per<-womenEnergy $clicked_out * 100

data_sum1 <- summarySE(womenEnergy, measurevar="clicked_out_per", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot2<-ggplot(data_sum1, aes(x=1, y= clicked_out_per, group=amp2)) + 
    geom_errorbar(aes(ymin= clicked_out_per-se, ymax= clicked_out_per +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Click-out rate") +
scale_y_continuous(limits = c(0, 10)) +
    ggtitle("Renewable energy \n Women respondents") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

grid.arrange(plot1 + annotate("text", x=0.975, y=3.2, label= "Gender-Balanced Council") + annotate("text", x = 1.025, y=8.5, label = "All-Male Council"), plot2 + annotate("text", x=0.975, y=4.7, label= "Gender-Balanced Council") + annotate("text", x = 1.025, y=3.2, label = "All-Male Council"), ncol=2)

##Figure 5 treatment effects moderated by abortion attitudes 

WomenReproSupport<-subset(womenRepro, abortion_support ==1) 

data_sum1 <- summarySE(WomenReproSupport, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot1<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Reproductive Health \n Pro-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

WomenEnergySupport<-subset(womenEnergy, abortion_support ==1) 

data_sum1 <- summarySE(WomenEnergySupport, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot2<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Renewable Energy \n Pro-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

WomenReproAgainst<-subset(womenRepro, abortion_support ==0) 

data_sum1 <- summarySE(WomenReproAgainst, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot3<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Reproductive Health  \n  Anti-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))


WomenEnergyAgainst<-subset(womenEnergy, abortion_support ==0) 

data_sum1 <- summarySE(WomenEnergyAgainst, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot4<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Renewable Energy  \n  Anti-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))


grid.arrange(plot1 + annotate("text", x=0.975, y=2.7, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3, label = "All-Male Council", size=2.5), plot2 + annotate("text", x=0.975, y=2.6, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.5, label = "All-Male Council", size=2.5), plot3 + annotate("text", x=0.975, y=2.85, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.8, label = "All-Male Council", size=2.5), plot4 + annotate("text", x=0.975, y=2.85, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.6, label = "All-Male Council", size=2.5), ncol=2, nrow=2)


##Figure 6 treatment effects (women respondents on external efficacy)

data_sum1 <- summarySE(womenRepro, measurevar="efficacy", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right

plot1<-ggplot(data_sum1, aes(x=1, y= efficacy, group=amp2)) + 
    geom_errorbar(aes(ymin= efficacy-se, ymax= efficacy +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Perceived Efficacy") +
scale_y_continuous(limits = c(2, 3.5)) +
    ggtitle("Reproductive health \n Women respondents") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

##Women Energy

data_sum1 <- summarySE(womenEnergy, measurevar="efficacy", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot2<-ggplot(data_sum1, aes(x=1, y= efficacy, group=amp2)) + 
    geom_errorbar(aes(ymin= efficacy-se, ymax= efficacy +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Perceived Efficacy") +
scale_y_continuous(limits = c(2, 3.5)) +
    ggtitle("Renewable energy \n Women respondents") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

grid.arrange(plot1 + annotate("text", x=0.975, y=2.9, label= "Gender-Balanced Council") + annotate("text", x = 1.025, y=3.1, label = "All-Male Council"), plot2 + annotate("text", x=0.975, y=2.85, label= "Gender-Balanced Council") + annotate("text", x = 1.025, y=2.65, label = "All-Male Council"), ncol=2)


##Figure 7 (moderated by pre-treatment candidate type)

data_sum1 <- summarySE(WomenMakeDiff_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum1$Treatment<-c("Gender-balanced", "All-male")

plot1<-ggplot(data_sum1, aes(x=1, y= race_interest, group= amp)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.5)) +
    ggtitle("Reproductive health \n Make a difference") +
  theme(plot.title = element_text(size = 10)) +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())
 
data_sum1 <- summarySE(WomenEnjoy_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum1$Treatment<-c("Gender-balanced", "All-male")

plot2<-ggplot(data_sum1, aes(x=1, y= race_interest, group= amp)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.5)) +
    ggtitle("Reproductive health \n Enjoy the position") +
      theme(plot.title = element_text(size = 10)) +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())
   
data_sum1 <- summarySE(WomenWin_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum1$Treatment<-c("Gender-balanced", "All-male")

plot3<-ggplot(data_sum1, aes(x=1, y= race_interest, group= amp)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.5)) +
    ggtitle("Reproductive health \n Where I can win") +
      theme(plot.title = element_text(size = 10)) +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

data_sum1 <- summarySE(WomenMakeDiff_Energy, measurevar="race_interest", groupvars=c("amp"))
data_sum1$Treatment<-c("Gender-balanced", "All-male")

plot4<-ggplot(data_sum1, aes(x=1, y= race_interest, group= amp)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.5)) +
    ggtitle("Renewable energy \n Make a difference") +
      theme(plot.title = element_text(size = 10)) +
           theme(legend.position = "none") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank()) 

data_sum1 <- summarySE(WomenEnjoy_Energy, measurevar="race_interest", groupvars=c("amp"))
data_sum1$Treatment<-c("Gender-balanced", "All-male")

plot5<-ggplot(data_sum1, aes(x=1, y= race_interest, group= amp)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.5)) +
    ggtitle("Renewable energy \n Enjoy the position") +
      theme(plot.title = element_text(size = 10)) +
           theme(legend.position = "none") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank()) 
    
data_sum1 <- summarySE(WomenWin_Energy, measurevar="race_interest", groupvars=c("amp"))
data_sum1$Treatment<-c("Gender-balanced", "All-male")

plot6<-ggplot(data_sum1, aes(x=1, y= race_interest, group= amp)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.5)) +
    ggtitle("Renewable energy \n Where I can win") +
      theme(plot.title = element_text(size = 10)) +
           theme(legend.position = "none") +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank()) 

grid.arrange(plot1 + annotate("text", x=0.975, y=2.85, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3.1, label = "All-Male Council", size=2.5), 

plot4+ annotate("text", x=0.975, y=2.8, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.75, label = "All-Male Council", size=2.5),
plot2+ annotate("text", x=0.975, y=2.65, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.75, label = "All-Male Council", size=2.5), 
plot5+ annotate("text", x=0.975, y=2.55, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.3, label = "All-Male Council", size=2.5), 
plot3+ annotate("text", x=0.975, y=3.25, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3.2, label = "All-Male Council", size=2.5), 
plot6+ annotate("text", x=0.975, y=2.85, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.85, label = "All-Male Council", size=2.75), 
ncol=2, nrow=3) 

##Table of Figure 7 estimates. These summaries contain the point estimates, standard errors, and CATEs (difference between the point estimates) associated with Figure 7.

data_sum1 <- summarySE(WomenMakeDiff_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum2 <- summarySE(WomenMakeDiff_Energy, measurevar="race_interest", groupvars=c("amp"))
data_sum3 <- summarySE(WomenEnjoy_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum4 <- summarySE(WomenEnjoy_Energy, measurevar="race_interest", groupvars=c("amp"))
data_sum5 <- summarySE(WomenWin_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum6 <- summarySE(WomenWin_Energy, measurevar="race_interest", groupvars=c("amp"))

TableFig7<-rbind(
data_sum1,
data_sum2,
data_sum3,
data_sum4,
data_sum5,
data_sum6)

xtable(TableFig7)


#Figure 8: effects moderated by party ID 

data_sum <- summarySE(womenRepro, measurevar="race_interest", groupvars=c("amp","party_scale"))
data_sum$party_scale<-recode(data_sum$party_scale, " 1='1. Dem'; 2 = '2. Lean Dem'; 3 = '3. Independent'; 4 = '4. Lean Rep'; 5 = '5. Rep'  ")
data_sum$Treatment<-recode(data_sum$amp, " 0 = 'Gender Balanced Panel'; 1 = 'All Male Panel'  ")

# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right

breaks<-seq(1,5,1)

ggplot(data_sum, aes(x= party_scale, y= race_interest, colour= Treatment, group= Treatment)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), width=.1, position=pd) +
    geom_line(position=pd) +
    geom_point(position=pd, shape=16, aes(size=N), show.legend=FALSE) + # 21 is filled circle
    xlab("Party ID") +
   ylab("Average Interest in Race") +
     ggtitle("Women Respodents by Party ID: Reproductive Health") +
    theme_bw() +
    scale_colour_grey(end= 0.7) +
    theme(legend.position=c(0.15,0.2))    +            # Position legend in bottom right
    scale_y_continuous(limits = c(1, 4))
    
 ##Table of Figure 8 estimates. The summaries in "data_sum" contain the point estimates, standard errors, and CATEs (difference between the point estimates) associated with Figure 8.

data_sum
 
 xtable (data_sum)
 


##Figure 9: effects moderated by race / ethnicity 

BlackWomen<-subset(women, race_eth=="Black or African American") #n=165
BlackWomenRepro<-subset(BlackWomen, repro==1) 

data_sum1 <- summarySE(BlackWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot1<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Reproductive Health \n Black Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

BlackWomenEnergy<-subset(BlackWomen, repro==0) 

data_sum1 <- summarySE(BlackWomenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot2<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Renewable Energy \n  Black Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

LatinaWomen<-subset(women, race_eth=="Hispanic or Latino")
LatinaWomenRepro<-subset(LatinaWomen, repro==1) 

data_sum1 <- summarySE(LatinaWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot3<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Reproductive Health \n Hispanic / Latina Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

LatinaWomenEnergy<-subset(LatinaWomen, repro==0) 

data_sum1 <- summarySE(LatinaWomenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot4<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Renewable Energy \n  Hispanic / Latina Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

WhiteWomen<-subset(women, race_eth=="White")
WhiteWomenRepro<-subset(WhiteWomen, repro==1) 

data_sum1 <- summarySE(WhiteWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot5<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Reproductive Health \n White Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

WhiteWomenEnergy<-subset(WhiteWomen, repro==0) 

data_sum1 <- summarySE(WhiteWomenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot6<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1.75, 3.25)) +
    ggtitle("Renewable Energy \n  White Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

grid.arrange(plot1 + annotate("text", x=0.975, y=2.75, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3.1, label = "All-Male Council", size=2.5), plot2 + annotate("text", x=0.975, y=2.85, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.6, label = "All-Male Council", size=2.5), plot3 + annotate("text", x=0.975, y=3, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3, label = "All-Male Council", size=2.5), plot4 + annotate("text", x=0.975, y=2.9, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.9, label = "All-Male Council", size=2.5), plot5 + annotate("text", x=0.975, y=2.75, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3, label = "All-Male Council", size=2.5), plot6 + annotate("text", x=0.975, y=2.5, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.55, label = "All-Male Council", size=2.5), ncol=2, nrow=3)

 ##Table of Figure 9 estimates. The summaries in "data_sum" contain the point estimates, standard errors, and CATEs (difference between the point estimates) associated with Figure 9.

data_sum1 <- summarySE(BlackWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum2 <- summarySE(BlackWomenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum3 <- summarySE(LatinaWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum4 <- summarySE(LatinaWomenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum5 <- summarySE(WhiteWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum6 <- summarySE(WhiteWomenEnergy, measurevar="race_interest", groupvars=c("amp"))

data_sum1
data_sum2
data_sum3
data_sum4
data_sum5
data_sum6

Fig9Table<-rbind(
data_sum1,
data_sum2,
data_sum3,
data_sum4,
data_sum5,
data_sum6)

xtable(Fig9Table)


##CES replication 

CES<-as.data.frame(read.spss("CCES.sav")) #load full CES data set
CES <-CES[,c(5:8, 238, 241, 381:413)] #select variables associated with study module
CES <-CES[,c(1:7, 11, 12, 34:39)]

names<-c( 'birthyr', 'gender', 'educ', 'race', 'pid3', 'pid7', 'treatment', 'FemID', 'FemStrength', 'AmbPre', 'NewMem', 'Efficacy', 'RunRace', 'AmbPost', 'WomenOffice')
names(CES)<-names

#clearn / recode data

CES $RunRace <-as.character(CES $RunRace)

CES[CES =="Not at all interested"]<-1
CES[CES =="Not very interested"]<-2
CES[CES =="Somewhat interested"]<-3
CES[CES =="Very interested"]<-4

CES $RunRace <-as.numeric(as.character(CES $RunRace))

CES $AMP<-recode(CES $treatment, " c('Vignette 1', 'Vignette 3') = 1; c('Vignette 2', 'Vignette 4') = 0")
CES $AMP<-as.numeric(as.character(CES $AMP))

CES $Repro<-recode(CES $treatment, " c('Vignette 1', 'Vignette 2') = 0; c('Vignette 3', 'Vignette 4') = 1")
CES $Repro<-as.numeric(as.character(CES $Repro))

CESwomen<-subset(CES, gender=="Female")
CESmen<-subset(CES, gender=="Male")


##Table 4: Replicating core results using CES data

lm1<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= CESwomen) 
summary(lm1) # 

lm2<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= CESmen) 
summary(lm2) #

screenreg(list(lm1, lm2), stars = c(0.01, 0.05, 0.1), digits = 3)
texreg(list(lm1, lm2), stars = c(0.01, 0.05, 0.1), digits = 3)

###########################
######SI Analyses #######
##########################

#Code first replicates all SI figures, followed by all SI tables 

#SI FIGURES##

##Figure SI.1: CATES for women by education level (Dynata data)

data_sum <- summarySE(womenRepro, measurevar="race_interest", groupvars=c("amp","edu_scale"))

data_sum$edu_scale <-recode(data_sum$edu_scale, " 1='1. HS or less'; 2 = '2. Some College'; 3 = '3. Two-year degree'; 4 = '4. Four-year degree' ; 5 = '5. Post-grad degree'  ")
data_sum$Treatment<-recode(data_sum$amp, " 0 = 'Gender Balanced Panel'; 1 = 'All Male Panel'  ")

# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right

breaks<-seq(1,5,1)

ggplot(data_sum, aes(x= edu_scale, y= race_interest, colour= Treatment, group= Treatment)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), width=.1, position=pd) +
    geom_line(position=pd) +
    geom_point(position=pd, shape=16, aes(size=N), show.legend=FALSE) + # 21 is filled circle
    xlab("Education Level") +
   ylab("Average Interest in Race") +
     ggtitle("Women Respodents by Education Level: Reproductive Health") +
    theme_bw() +
    scale_colour_grey(end= 0.7) +
    theme(legend.position=c(0.15,0.2))    +            # Position legend in bottom right
    scale_y_continuous(limits = c(1, 4))


## Figure S1.2: CATES for women by pre-treatment political interest level (Dynata data)

data_sum <- summarySE(womenRepro, measurevar="race_interest", groupvars=c("amp","pol_interest_scale"))

data_sum$pol_interest_scale <-recode(data_sum$pol_interest_scale, " 1='1. Hardly at all'; 2 = '2. Only now and then'; 3 = '3 .Some of the time'; 4 = '4. Most of the time'  ")
data_sum$Treatment<-recode(data_sum$amp, " 0 = 'Gender Balanced Panel'; 1 = 'All Male Panel'  ")

# The errorbars overlapped, so use position_dodge to move them horizontally
pd <- position_dodge(0.1) # move them .05 to the left and right

breaks<-seq(1,5,1)

ggplot(data_sum, aes(x= pol_interest_scale, y= race_interest, colour= Treatment, group= Treatment)) + 
    geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), width=.1, position=pd) +
    geom_line(position=pd) +
    geom_point(position=pd, shape=16, aes(size=N), show.legend=FALSE) + # 21 is filled circle
    xlab("Political Interest") +
   ylab("Average Interest in Race") +
     ggtitle("Women Respodents by Political Interest: Reproductive Health") +
    theme_bw() +
    scale_colour_grey(end= 0.7) +
    theme(legend.position=c(0.15,0.2))    +            # Position legend in bottom right
    scale_y_continuous(limits = c(1, 4))

##Figure S1.3: CATES for women by abortion attitudes and race / ethnicity (Dynata data)

BlackWomenReproSupport<-subset(BlackWomenRepro, abortion_support ==1) 

data_sum1 <- summarySE(BlackWomenReproSupport, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot1<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health \n Pro-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

BlackWomenReproAgainst<-subset(BlackWomenRepro, abortion_support ==0) 

data_sum1 <- summarySE(BlackWomenReproAgainst, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot2<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health  \n  Anti-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

LatinaWomenReproSupport<-subset(LatinaWomenRepro, abortion_support ==1) 

data_sum1 <- summarySE(LatinaWomenReproSupport, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot3<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health \n Pro-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

LatinaWomenReproAgainst<-subset(LatinaWomenRepro, abortion_support ==0) 

data_sum1 <- summarySE(LatinaWomenReproAgainst, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot4<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health  \n  Anti-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))


WhiteWomenReproSupport<-subset(WhiteWomenRepro, abortion_support ==1) 

data_sum1 <- summarySE(WhiteWomenReproSupport, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot5<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health \n Pro-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

WhiteWomenReproAgainst<-subset(WhiteWomenRepro, abortion_support ==0) 

data_sum1 <- summarySE(WhiteWomenReproAgainst, measurevar="race_interest", groupvars=c("amp"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot6<-ggplot(data_sum1, aes(x=1, y= race_interest, group=amp2)) + 
  geom_errorbar(aes(ymin= race_interest-se, ymax= race_interest +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health  \n  Anti-Choice Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))+ 
    theme(plot.title = element_text(size = 10))

grid.arrange(plot1 + annotate("text", x=0.975, y=2.85, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3.2, label = "All-Male Council", size=2.5), plot2 + annotate("text", x=0.975, y=3.2, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3.2, label = "All-Male Council", size=2.5), plot3 + annotate("text", x=0.975, y=3.4, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3.5, label = "All-Male Council", size=2.5), plot4 + annotate("text", x=0.975, y=3.1, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3, label = "All-Male Council", size=2.5), plot5 + annotate("text", x=0.975, y=2.9, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3.2, label = "All-Male Council", size=2.5), plot6 + annotate("text", x=0.975, y=3, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=3, label = "All-Male Council", size=2.5), ncol=2, nrow=3)

## Figure S1.4: CATES for women by race / ethnicity (CES data)

BlackWomen<-subset(CESwomen, race=="Black")
WhiteWomen<-subset(CESwomen, race=="White")
LatinaWomen<-subset(CESwomen, race=="Hispanic")

BlackWomenRepro<-subset(BlackWomen, Repro==1) 
LatinaWomenRepro<-subset(LatinaWomen, Repro==1) 
WhiteWomenRepro<-subset(WhiteWomen, Repro==1) 

BlackWomenEnergy<-subset(BlackWomen, Repro==0) 
BlackWomenEnergy<-na.omit(BlackWomenEnergy)

LatinaWomenEnergy<-subset(LatinaWomen, Repro==0) 
WhiteWomenEnergy<-subset(WhiteWomen, Repro==0) 

pd <- position_dodge(0.1) # move them .05 to the left and right

data_sum1 <- summarySE(BlackWomenRepro, measurevar="RunRace", groupvars=c("AMP"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot1<-ggplot(data_sum1, aes(x=1, y= RunRace, group=amp2)) + 
  geom_errorbar(aes(ymin= RunRace-se, ymax= RunRace +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health \n Black Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))

LatinaWomenEnergy<-subset(LatinaWomen, Repro==0) 

data_sum1 <- summarySE(BlackWomenEnergy, measurevar="RunRace", groupvars=c("AMP"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot2<-ggplot(data_sum1, aes(x=1, y= RunRace, group=amp2)) + 
  geom_errorbar(aes(ymin= RunRace-se, ymax= RunRace +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Renewable Energy \n  Black Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))

library(grid)
require(gridExtra)

data_sum1 <- summarySE(LatinaWomenRepro, measurevar="RunRace", groupvars=c("AMP"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot3<-ggplot(data_sum1, aes(x=1, y= RunRace, group=AMP)) + 
  geom_errorbar(aes(ymin= RunRace-se, ymax= RunRace +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health \n Latina Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))

data_sum1 <- summarySE(LatinaWomenEnergy, measurevar="RunRace", groupvars=c("AMP"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot4<-ggplot(data_sum1, aes(x=1, y= RunRace, group=AMP)) + 
  geom_errorbar(aes(ymin= RunRace-se, ymax= RunRace +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Renewable Energy \n  Latina Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))
library(grid)

data_sum1 <- summarySE(WhiteWomenRepro, measurevar="RunRace", groupvars=c("AMP"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot5<-ggplot(data_sum1, aes(x=1, y= RunRace, group=AMP)) + 
  geom_errorbar(aes(ymin= RunRace-se, ymax= RunRace +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Reproductive Health \n White Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))

data_sum1 <- summarySE(WhiteWomenEnergy, measurevar="RunRace", groupvars=c("AMP"))
data_sum1$amp2<-c("1_GBP", "2_AMP")

plot6<-ggplot(data_sum1, aes(x=1, y= RunRace, group=AMP)) + 
  geom_errorbar(aes(ymin= RunRace-se, ymax= RunRace +se), colour="black", width=.1, position=pd) +
    geom_line(position=pd) +
        geom_point(position=pd, size=3, shape=21, fill="white") + # 21 is filled circle
    xlab("") +
    ylab("Average Interest in Race") +
scale_y_continuous(limits = c(1, 4)) +
    ggtitle("Renewable Energy \n  White Women")+
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank(),
        axis.text.y=element_text(size=5))

library(grid)

grid.arrange(plot1 + annotate("text", x=0.975, y=2.55, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.85, label = "All-Male Council", size=2.5), plot2 + annotate("text", x=0.975, y=2.9, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.45, label = "All-Male Council", size=2.5), plot3 + annotate("text", x=0.975, y=3.1, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.95, label = "All-Male Council", size=2.5), plot4 + annotate("text", x=0.975, y=2.8, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.5, label = "All-Male Council", size=2.5), plot5 + annotate("text", x=0.975, y=2.65, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.75, label = "All-Male Council", size=2.5), plot6 + annotate("text", x=0.975, y=2.65, label= "Gender-Balanced \n Council", size=2.5) + annotate("text", x = 1.025, y=2.45, label = "All-Male Council", size=2.5), ncol=2, nrow=3)


##SI Tables###

##Table S1.1: Education level CATE Table 

data_sum <- summarySE(womenRepro, measurevar="race_interest", groupvars=c("amp","edu_scale"))

data_sum$edu_scale <-recode(data_sum$edu_scale, " 1='1. HS or less'; 2 = '2. Some College'; 3 = '3. Two-year degree'; 4 = '4. Four-year degree' ; 5 = '5. Post-grad degree'  ")
data_sum$Treatment<-recode(data_sum$amp, " 0 = 'Gender Balanced Panel'; 1 = 'All Male Panel'  ")

xtable(data_sum)

##Table S1.2: Political interest CATE table 

data_sum <- summarySE(womenRepro, measurevar="race_interest", groupvars=c("amp","pol_interest_scale"))

data_sum$pol_interest_scale <-recode(data_sum$pol_interest_scale, " 1='1. Hardly at all'; 2 = '2. Only now and then'; 3 = '3 .Some of the time'; 4 = '4. Most of the time'  ")
data_sum$Treatment<-recode(data_sum$amp, " 0 = 'Gender Balanced Panel'; 1 = 'All Male Panel'  ")

xtable(data_sum)


#Table S1.3: Difference-in-difference test for effects among pro-choice women. Sample includes women respondents who reported that limiting access to abortion was “a bad idea.” Dynata data. 

ProWomen<-subset(women, abortion_support ==1)
AntiWomen<-subset(women, abortion_support ==0)

lm1<-lm(race_interest ~ amp * repro , data= ProWomen) 
summary(lm1) 

#Table S1.4: Treatment effects for women respondents on interest in hypothetical race by pre-treatment can- didate type (See Figure 7 in text) 
data_sum1 <- summarySE(WomenMakeDiff_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum2 <- summarySE(WomenMakeDiff_Energy, measurevar="race_interest", groupvars=c("amp"))
data_sum3 <- summarySE(WomenEnjoy_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum4 <- summarySE(WomenEnjoy_Energy, measurevar="race_interest", groupvars=c("amp"))
data_sum5 <- summarySE(WomenWin_Repro, measurevar="race_interest", groupvars=c("amp"))
data_sum6 <- summarySE(WomenWin_Energy, measurevar="race_interest", groupvars=c("amp"))

TableFig7<-rbind(
data_sum1,
data_sum2,
data_sum3,
data_sum4,
data_sum5,
data_sum6)

xtable(TableFig7)

#Table S1.5: Conditional average treatment effects for women respondents on interest in hypothetical race by party identification (See Figure 8 in text)
data_sum <- summarySE(womenRepro, measurevar="race_interest", groupvars=c("amp","party_scale"))
data_sum$party_scale<-recode(data_sum$party_scale, " 1='1. Dem'; 2 = '2. Lean Dem'; 3 = '3. Independent'; 4 = '4. Lean Rep'; 5 = '5. Rep'  ")
data_sum$Treatment<-recode(data_sum$amp, " 0 = 'Gender Balanced Panel'; 1 = 'All Male Panel'  ")
xtable(data_sum)

#Table S1.6: Conditional treatment effects for women respondents on interest in hypothetical race by respondent race / ethnicity. (See Figure 9 in text)
data_sum1 <- summarySE(BlackWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum2 <- summarySE(BlackWomenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum3 <- summarySE(LatinaWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum4 <- summarySE(LatinaWomenEnergy, measurevar="race_interest", groupvars=c("amp"))
data_sum5 <- summarySE(WhiteWomenRepro, measurevar="race_interest", groupvars=c("amp"))
data_sum6 <- summarySE(WhiteWomenEnergy, measurevar="race_interest", groupvars=c("amp"))

Fig9Table<-rbind(
data_sum1,
data_sum2,
data_sum3,
data_sum4,
data_sum5,
data_sum6)

xtable(Fig9Table)

#Table SI.7 Abortion stance / Race & Ethnicity CATE table 

data_sum1 <- summarySE(BlackWomenReproSupport, measurevar="race_interest", groupvars=c("amp"))
data_sum2 <- summarySE(BlackWomenReproAgainst, measurevar="race_interest", groupvars=c("amp"))
data_sum3 <- summarySE(LatinaWomenReproSupport, measurevar="race_interest", groupvars=c("amp"))
data_sum4 <- summarySE(LatinaWomenReproAgainst, measurevar="race_interest", groupvars=c("amp"))
data_sum5 <- summarySE(WhiteWomenReproSupport, measurevar="race_interest", groupvars=c("amp"))
data_sum6 <- summarySE(WhiteWomenReproAgainst, measurevar="race_interest", groupvars=c("amp"))

TableFigRaceAbortion<-rbind(
data_sum1,
data_sum2,
data_sum3,
data_sum4,
data_sum5,
data_sum6)

xtable(TableFigRaceAbortion)


#Table S1.8: CATEs for DV of political efficacy by race / ethnicity (Dynata data)

lm1<-lm(efficacy ~ amp + repro + I(amp*repro), data=LatinaWomen) # 
summary(lm1) #

lm2<-lm(efficacy ~ amp + repro + I(amp*repro), data=BlackWomen) # sig
summary(lm2) #

lm3<-lm(efficacy ~ amp + repro + I(amp*repro), data=WhiteWomen) # sig
summary(lm3) #

screenreg(list(lm1, lm2, lm3), stars = c(0.01, 0.05, 0.1), digits = 3)
texreg(list(lm1, lm2, lm3), stars = c(0.01, 0.05, 0.1), digits = 3)


#Table S1.9: CATEs by party for women respondents (CES data)

DemWomen<-subset(CESwomen, pid7 == "Strong Democrat" | pid7 == "Not very strong Democrat ")
DemLeanWomen<-subset(CESwomen, pid7 == "Lean Democrat")
IndependentWomen<-subset(CESwomen, pid7 == "Independent")
RepLeanWomen<-subset(CESwomen, pid7 == "Lean Republican")
RepWomen<-subset(CESwomen, pid7 == "Strong Republican" | pid7 == "Not very strong Republican ")

lm1<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= DemWomen) 
summary(lm1) # 

lm2<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= DemLeanWomen) 
summary(lm3) #

lm3<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= IndependentWomen) 
summary(lm2) #sig at 0.02, not sig for WOC, but sig for Black women  

lm4<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= RepLeanWomen) 
summary(lm4) #

lm5<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= RepWomen) 
summary(lm5) #

screenreg(list(lm1, lm2, lm3, lm4, lm5), stars = c(0.01, 0.05, 0.1), digits = 3)
texreg(list(lm1, lm2, lm3, lm4, lm5), stars = c(0.01, 0.05, 0.1), digits = 3)

#Table S1.10: CATEs by race / ethnicity for women respondents (CES data) 

BlackWomen<-subset(women, race=="Black")
WhiteWomen<-subset(women, race=="White")
LatinaWomen<-subset(women, race=="Hispanic")


lm1<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= WhiteWomen) #sig at 0.08 for white women
summary(lm1) # 

lm2<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= BlackWomen) #sig at 0.02 for Black owmen
summary(lm2) #sig at 0.02, not sig for WOC, but sig for Black women  

lm3<-lm(RunRace ~ AMP + Repro + I(AMP * Repro), data= LatinaWomen) #not sig for Latinas 
summary(lm3) #

screenreg(list(lm1, lm2, lm3), stars = c(0.01, 0.05, 0.1), digits = 3)
texreg(list(lm1, lm2, lm3), stars = c(0.01, 0.05, 0.1), digits = 3)


#Table SI.11 Abortion stance / Race & Ethnicity CATE table 

data_sum1 <- summarySE(BlackWomenRepro, measurevar="RunRace", groupvars=c("AMP"))
data_sum2 <- summarySE(BlackWomenEnergy, measurevar="RunRace", groupvars=c("AMP"))
data_sum3 <- summarySE(LatinaWomenRepro, measurevar="RunRace", groupvars=c("AMP"))
data_sum4 <- summarySE(LatinaWomenEnergy, measurevar="RunRace", groupvars=c("AMP"))
data_sum5 <- summarySE(WhiteWomenRepro, measurevar="RunRace", groupvars=c("AMP"))
data_sum6 <- summarySE(WhiteWomenEnergy, measurevar="RunRace", groupvars=c("AMP"))

TableFigCESRaceEfficacy<-rbind(
data_sum1,
data_sum2,
data_sum3,
data_sum4,
data_sum5,
data_sum6)

xtable(TableFigCESRaceEfficacy)
